"use strict";

$(function () {
    "use strict";

    // 手机页面开始

    var goodsList = $(".goods-list-wrap");
    var priceUp = $(".priceUp");
    var priceDown = $(".priceDown");
    $.ajax({
        url: "../data/phoneCont.json",
        type: "get",
        success: function success(res) {
            // console.log(priceUp)
            // console.log(priceDown)
            priceUp.click(function () {
                res.sort(function (a, b) {
                    return a.price.replace('￥', '') - b.price.replace('￥', '');
                });
                display();
            });
            priceDown.click(function () {
                res.sort(function (a, b) {
                    return b.price.replace('￥', '') - a.price.replace('￥', '');
                });
                display();
            });

            display();
            function display() {
                var str = "";
                res.forEach(function (index, value) {
                    str += " <li class=\"gl-item\">\n                    <a href=\"\" class=\"gl-item-link\">\n                        <img src=\"" + res[value].img + "\">\n                        <ul class=\"item-slide\">\n                            <li class=\"item-silde-dot\"></li>\n                        </ul>\n                        <h3 class=\"item-title\">" + res[value].title + "</h3>\n                        <p class=\"item-desc\">" + res[value].desc + "</p>\n                        <p class=\"item-price\">" + res[value].price + "</p>\n                        <p class=\"hot-sale " + res[value].signColor + "\">" + res[value].sign + "</p>\n                    </a>\n                </li>";
                });
                goodsList.html(str);
            }
        }

    });

    // 手机页面推荐控制按钮
    var recommend_L = $(".recommend-slider ul");
    var recommend_C = $(".recommend-control li");

    recommend_C.click(function () {
        $(this).addClass("active").siblings().removeClass("active");
        // console.log($(this).index())
        recommend_L.animate({
            left: -$(this).index() * 930
        }, 500);
    });

    // 手机页面结束
});